<!--
 * @Author: liu
 * @Date: 2024-06-23 18:45:39
 * @LastEditors: liu
 * @LastEditTime: 2024-06-23 23:21:18
 * @FilePath: \yyx_admin\src\views\courses\components\LessonDelDlg.vue
 * @Description: 
 * 天道酬勤
-->
<template>
  <div>
    <el-dialog
      v-model="dialogFormVisible"
      width="400"
      height="200"
      center
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <span>确认要删除此课时么？</span>
      <template #footer>
        <div class="dialog-footer">
          <el-button style="color: #606266" @click="dialogFormVisible = false"
            >取消</el-button
          >
          <el-button type="primary" @click="onSubmit"> 确认 </el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup lang="ts">
import { reactive, ref } from 'vue'
import { saveOrUpdateLesson } from '@/api/course/index'
import { ElMessage } from 'element-plus'

const dialogFormVisible = ref(false)
const form = reactive({
  status: 0
})

//声明事件消息
const emits = defineEmits<{
  (e: 'lessonStatus'): void
}>()

//对话框初始化
const showAndInit = (data: any) => {
  // console.log(courseInfo, lessonInfo)

  Object.assign(form, data)
  dialogFormVisible.value = true
}

const onSubmit = async () => {
  const res = await saveOrUpdateLesson(form)
  if (res.code === 0) {
    ElMessage({
      type: 'success',
      message: `更新课时状态成功！`
    })
    dialogFormVisible.value = false
    emits('lessonStatus')
  } else {
    ElMessage({
      type: 'error',
      message: `更新课时状态失败！`
    })
    throw new Error('更新课时状态失败')
  }
}
defineExpose({
  showAndInit
})
</script>

<style scoped></style>
